﻿#if NETSTANDARD2_0 || NETCOREAPP3_0
using Microsoft.Extensions.DependencyInjection;
using System;
#endif

namespace Longbow.Data
{
    /// <summary>
    /// 业务实体类上下文，通过不同的数据库配置文件创建不同的业务实体类
    /// </summary>
    public static class DbContextManager
    {

#if NETSTANDARD2_0 || NETCOREAPP3_0
        /// <summary>
        /// 配置文件如果启用Widget配置，T.FullName 必须是 {AssemblyName}.{ClassName} 并且继承DataAccess类下的T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Create<T>() => DatabaseServiceCollectionExtensions.ServiceProvider.GetRequiredService<IDbContext<T>>().Create();
#else
        /// <summary>
        /// 配置文件如果启用Widget配置，T.FullName 必须是 {AssemblyName}.{ClassName} 并且继承DataAccess类下的T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Create<T>() where T : class => new DefaultDbContext<T>().Create();
#endif
    }
}
